/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package be.wiim.mqtt;

import java.util.Date;

/**
 *
 * @author wimvandecasteele
 */
public class PiMQTTExample {

    public static void main(String[] args) throws Exception {
           try
           {   
                String vBrokerIP = args[0];
                String vClientId = args[1];
                String vIsPublisher = args[2];
                String vTopic = args[3];
                
                if(vIsPublisher.equals("1"))
                {
                    Publisher vPublisher = new Publisher(vClientId,vBrokerIP,vTopic);
                    while(true)
                    {
                        vPublisher.publish(new Date() + "");
                        Thread.sleep(10000);
                    }
                }
                else
                {
                    Subscriber vSubscriber = new Subscriber(vClientId,vBrokerIP);
                    vSubscriber.subscribe(vTopic,0);
                    while(true)
                    {//Keep listening   
                    }
                }
           }
           catch(Exception ex)
           {
               ex.printStackTrace();
               throw new Exception("Invalid params! <broker-ip> <client-id> <1|0> <topic>");
           }
           
	}
}
